package com.hgy.commonsale.service.impl;

import java.util.List;

import org.geln.web.hibernate.BaseHibernateService;
import org.geln.web.status.Status;
import com.hgy.commonsale.product.GoodKinds;
import com.hgy.commonsale.service.GoodKindManagerService;

import util.CommonUtil;

public class GoodKindManagerServiceImpl extends BaseHibernateService implements
		GoodKindManagerService {

	public Object saveObject(GoodKinds kind) {

		if (validateExists(kind.getGoodKindName())) {
			return null;
		}else{
			getHibernateTemplate().save(kind);
			return Status.SUCCESS;
		}
	}

	
	public Object updateObject() {
		return null;
	}

	/**
	 * ��֤�Ƿ����
	 * 
	 * @param kindName
	 * @return
	 */
	private Boolean validateExists(String kindName) {
		boolean flag = false;
		if (getKindByKindName(kindName) != null) {
			flag = true;
		}

		return flag;
	}

	/**
	 * ͨ����Ʒ�����ƻ�ȡ��Ʒ���ʵ��
	 * 
	 * @param:kindName:��Ʒ������
	 * @return:GoodKinds:��Ʒ���ʵ��
	 */
	public GoodKinds getKindByKindName(String kindName) {

		String strQuery = "from GoodKinds where goodKindName=?";
		
		List<GoodKinds> lstGoodKinds = getHibernateTemplate().find(strQuery,new String[]{kindName});

		if (lstGoodKinds!=null && lstGoodKinds.size() > 0) {
			return lstGoodKinds.get(0);
		}

		return null;
	}

	public List<GoodKinds> getKindsList() {
		String strQuery = "from GoodKinds";
		List<GoodKinds> lstGoodkinds = getHibernateTemplate().find(strQuery);

		return lstGoodkinds;
	}

	public Status deleteObjectByName(String kindName) {
		GoodKinds goodKinds = getKindByKindName(kindName);
		if (CommonUtil.isNotEmpty(goodKinds)) {
			getHibernateTemplate().delete(goodKinds);
			return Status.SUCCESS;
		}

		return Status.FAILED;

	}

	public Status deleteObjectByPK(String pk) {
		return null;
	}

}
